Skip to content

test(suite): set up initial testsuite#36

Merged
Datata1 merged 10 commits intomainfrom
testing/testsuite
Feb 7, 2026
Merged

test(suite): set up initial testsuite#36
Datata1 merged 10 commits intomainfrom
testing/testsuite

Conversation

@Datata1
Copy link
Owner

@Datata1 Datata1 commented Feb 3, 2026

No description provided.

@Datata1 Datata1 self-assigned this Feb 3, 2026
@github-actions
Copy link

github-actions bot commented Feb 3, 2026

🛡️ Bandit Security Scan Results

✅ No security issues found by Bandit.

@Datata1 Datata1 requested a review from Copilot February 3, 2026 13:41
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR establishes a comprehensive test suite for the Codesphere Python SDK, including both unit and integration tests. The changes refactor the SDK's internal architecture to support lazy operation loading (avoiding circular imports), add extensive test coverage across all resource types, and provide integration test infrastructure with automated workspace setup/cleanup.

Changes:

  • Set up complete test infrastructure with unit and integration tests covering Teams, Workspaces, Domains, Environment Variables, and Metadata resources
  • Refactored SDK internals to use lazy operation loading via _execute_operation() method, eliminating circular import issues
  • Added integration test workflow with session-scoped test workspace management and environment variable configuration
  • Updated documentation with testing guidelines and separated command schemas to resolve import cycles

Reviewed changes

Copilot reviewed 70 out of 87 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
tests/test_client.py Migrated client tests to class-based structure with improved fixtures
tests/resources/workspace/test_workspace.py Added comprehensive workspace resource unit tests
tests/resources/workspace/env_vars/test_env_vars.py Added environment variables manager unit tests
tests/resources/team/test_team.py Added team resource unit tests
tests/resources/team/domain/test_domain.py Added domain resource unit tests
tests/resources/metadata/test_metadata.py Added metadata resource unit tests
tests/integration/test_*.py Added integration tests for all major resources
tests/integration/conftest.py Added session-scoped workspace fixtures for integration tests
tests/conftest.py Added shared test fixtures and mock factories
tests/resources/conftest.py Added resource-specific test fixtures
src/codesphere/resources/workspace/schemas.py Refactored to use lazy operation loading and separated command schemas
src/codesphere/resources/workspace/command_schemas.py Extracted command-related schemas to avoid circular imports
src/codesphere/resources/workspace/envVars/schemas.py Separated EnvVar schema to avoid circular imports
src/codesphere/resources/workspace/envVars/models.py Refactored to use lazy operation loading
src/codesphere/resources/metadata/schemas.py Added explicit Field validation aliases for CPU/RAM/etc fields
src/codesphere/core/handler.py Enhanced null checks and removed debug logging
src/codesphere/core/base.py Added serialize_by_alias configuration
src/codesphere/config.py Added extra="ignore" to allow additional CS_* env vars
Makefile Added test-unit and test-integration targets
.github/workflows/integration.yml Added integration test GitHub Actions workflow
CONTRIBUTING.md Added comprehensive testing guidelines section
examples/* Removed example files (likely to be regenerated)

@github-actions
Copy link

github-actions bot commented Feb 7, 2026

Coverage

Pytest Coverage Report
FileStmtsMissCoverMissing
src/codesphere
   client.py220100% 
   config.py90100% 
   exceptions.py7357%11–12, 16
   http_client.py54590%80–81, 83–85
   utils.py271640%12–13, 26–32, 34–35, 40–43, 45
src/codesphere/core
   base.py190100% 
   handler.py911385%118–120, 125–130, 136–137, 140–141
   operations.py110100% 
src/codesphere/resources/metadata
   operations.py60100% 
   resources.py200100% 
   schemas.py280100% 
src/codesphere/resources/team
   operations.py60100% 
   resources.py170100% 
   schemas.py260100% 
src/codesphere/resources/team/domain
   manager.py300100% 
   operations.py100100% 
   resources.py31487%45, 48–50
   schemas.py350100% 
src/codesphere/resources/workspace
   operations.py110100% 
   resources.py180100% 
   schemas.py760100% 
src/codesphere/resources/workspace/envVars
   models.py32293%39–40
   operations.py60100% 
   schemas.py40100% 
src/codesphere/resources/workspace/landscape
   models.py00100% 
   resources.py00100% 
src/codesphere/resources/workspace/pipeline
   models.py00100% 
   resources.py00100% 
TOTAL5964392% 

Test Execution Summary

Tests Skipped Failures Errors Time
112 0 💤 0 ❌ 0 🔥 1.435s ⏱️

@github-actions
Copy link

github-actions bot commented Feb 7, 2026

Integration Test Results

26 tests   26 ✅  50s ⏱️
 1 suites   0 💤
 1 files     0 ❌

Results for commit ac2df3c.

♻️ This comment has been updated with latest results.

@Datata1 Datata1 requested a review from Copilot February 7, 2026 11:47
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 63 out of 81 changed files in this pull request and generated 6 comments.

default=_BULK_SET_OP,
exclude=True,
)
return await self._execute_operation(_GET_OP)
Copy link

Copilot AI Feb 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WorkspaceEnvVarManager.get() is annotated to return List[EnvVar] but it returns the raw operation result. If _GET_OP returns ResourceList[EnvVar] (consistent with other list endpoints), callers will receive a ResourceList instead of a list. Consider mirroring other resources: result = await ...; return result.root (or change the return annotation/docstring to ResourceList[EnvVar]). This also makes the behavior consistent with TeamsResource.list() / WorkspacesResource.list().

Suggested change
return await self._execute_operation(_GET_OP)
result: ResourceList[EnvVar] = await self._execute_operation(_GET_OP)
return result.root

Copilot uses AI. Check for mistakes.
Comment on lines 23 to 25
async def set(
self, env_vars: Union[ResourceList[EnvVar], List[Dict[str, str]]]
) -> None:
Copy link

Copilot AI Feb 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type hints for set()/delete() don’t include List[EnvVar], but the unit tests call these methods with lists of EnvVar instances. Updating the annotations to include List[EnvVar] (and possibly broadening to a Sequence[...]) will align the public API with actual supported usage and avoid confusing type-checker errors.

Copilot uses AI. Check for mistakes.
)
await self._execute_operation(_BULK_SET_OP, data=payload.model_dump())

async def delete(self, items: Union[List[str], ResourceList[EnvVar]]) -> None:
Copy link

Copilot AI Feb 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type hints for set()/delete() don’t include List[EnvVar], but the unit tests call these methods with lists of EnvVar instances. Updating the annotations to include List[EnvVar] (and possibly broadening to a Sequence[...]) will align the public API with actual supported usage and avoid confusing type-checker errors.

Copilot uses AI. Check for mistakes.
Comment on lines +45 to +92
def mock_http_client_for_resource(mock_response_factory):
"""
Create a configurable mock HTTP client for resource testing.

Returns a factory function that creates configured mock clients.
"""

def _create(response_data: Any, status_code: int = 200) -> MagicMock:
mock_client = MagicMock()
mock_response = mock_response_factory.create(
status_code=status_code,
json_data=response_data,
)
mock_client.request = AsyncMock(return_value=mock_response)
return mock_client

return _create


@pytest.fixture
def teams_resource_factory(mock_http_client_for_resource):
"""Factory for creating TeamsResource instances with mock data."""

def _create(response_data: Any):
from codesphere.resources.team import TeamsResource

mock_client = mock_http_client_for_resource(response_data)
resource = TeamsResource(http_client=mock_client)
return resource, mock_client

return _create


@pytest.fixture
def workspaces_resource_factory(mock_http_client_for_resource):
"""Factory for creating WorkspacesResource instances with mock data."""

def _create(response_data: Any):
from codesphere.resources.workspace import WorkspacesResource

mock_client = mock_http_client_for_resource(response_data)
resource = WorkspacesResource(http_client=mock_client)
return resource, mock_client

return _create


@pytest.fixture
Copy link

Copilot AI Feb 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixture (and several factories below it) duplicates implementations already present in tests/conftest.py with the same fixture names. Keeping two versions increases the chance of behavior drift and makes it harder to know which fixture is used (pytest will prefer the closest conftest.py). Consider reusing the root fixtures instead (e.g., remove the duplicates here, or rename these to resource-specific names and delegate to the shared factory).

Suggested change
def mock_http_client_for_resource(mock_response_factory):
"""
Create a configurable mock HTTP client for resource testing.
Returns a factory function that creates configured mock clients.
"""
def _create(response_data: Any, status_code: int = 200) -> MagicMock:
mock_client = MagicMock()
mock_response = mock_response_factory.create(
status_code=status_code,
json_data=response_data,
)
mock_client.request = AsyncMock(return_value=mock_response)
return mock_client
return _create
@pytest.fixture
def teams_resource_factory(mock_http_client_for_resource):
"""Factory for creating TeamsResource instances with mock data."""
def _create(response_data: Any):
from codesphere.resources.team import TeamsResource
mock_client = mock_http_client_for_resource(response_data)
resource = TeamsResource(http_client=mock_client)
return resource, mock_client
return _create
@pytest.fixture
def workspaces_resource_factory(mock_http_client_for_resource):
"""Factory for creating WorkspacesResource instances with mock data."""
def _create(response_data: Any):
from codesphere.resources.workspace import WorkspacesResource
mock_client = mock_http_client_for_resource(response_data)
resource = WorkspacesResource(http_client=mock_client)
return resource, mock_client
return _create
@pytest.fixture
@pytest.fixture

Copilot uses AI. Check for mistakes.
Comment on lines +73 to +75
def test_client_initialization(self, api_http_client, mock_token):
"""Client should initialize with token from settings."""
assert api_http_client._token == mock_token
Copy link

Copilot AI Feb 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test suite no longer covers the negative initialization path (e.g., missing/empty token leading to an authentication/config error). Adding a test for the failure case would improve coverage of client setup and prevent regressions in the settings/token handling logic.

Copilot generated this review using guidance from repository custom instructions.
@Datata1 Datata1 merged commit 14fac2e into main Feb 7, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant